//
//  ListenXqTableViewCell.m
//  news
//
//  Created by dllo on 16/3/17.
//  Copyright © 2016年 imacbookair. All rights reserved.
//

#import "ListenXqTableViewCell.h"

@implementation ListenXqTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.titleLabel = [[UILabel alloc] init];
        //        _titleLabel.backgroundColor = [UIColor cyanColor];
        [self.contentView addSubview:_titleLabel];
        _titleLabel.numberOfLines = 0;
        _titleLabel.font = [UIFont fontWithName:@"Hoefler Text" size:15];
        
        self.playtimesImg = [[UIImageView alloc] init];
        //        _playtimesImg.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:_playtimesImg];
        _playtimesImg.image = [UIImage imageNamed:@"playOne"];
        
        self.playtimesLabel = [[UILabel alloc] init];
        //        _playtimesLabel.backgroundColor = [UIColor blueColor];
        [self.contentView addSubview:_playtimesLabel];
        _playtimesLabel.font = [UIFont systemFontOfSize:15];
        _playtimesLabel.textColor = [UIColor grayColor];
        
        self.durationImg = [[UIImageView alloc] init];
        //        _durationImg.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:_durationImg];
        _durationImg.image = [UIImage imageNamed:@"timeOne"];
        
        self.durationLabel = [[UILabel alloc] init];
        //        _durationLabel.backgroundColor = [UIColor blueColor];
        [self.contentView addSubview:_durationLabel];
        _durationLabel.font = [UIFont systemFontOfSize:15];
        _durationLabel.textColor = [UIColor grayColor];
        
        self.commentsImg = [[UIImageView alloc] init];
        //        _commentsImg.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:_commentsImg];
        _commentsImg.image = [UIImage imageNamed:@"commentOne"];
        
        self.commentsLabel = [[UILabel alloc] init];
        //        _commentsLabel.backgroundColor = [UIColor blueColor];
        [self.contentView addSubview:_commentsLabel];
        _commentsLabel.font = [UIFont systemFontOfSize:15];
        _commentsLabel.textColor = [UIColor grayColor];
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    CGFloat h = [ListenXqTableViewCell heightWithText:_titleLabel.text width:self.contentView.frame.size.width - 20];
    _titleLabel.frame = CGRectMake(10, 5, self.contentView.frame.size.width - 20, h);
    _playtimesImg.frame = CGRectMake(10, 12.5 + h, 20, 20);
    _playtimesLabel.frame = CGRectMake(30, 10 + h, 50, 25);
    _durationImg.frame = CGRectMake(90, 12.5 + h, 20, 20);
    _durationLabel.frame = CGRectMake(110, 10 + h, 60, 25);
    _commentsImg.frame = CGRectMake(180, 12.5 + h, 20, 20);
    _commentsLabel.frame = CGRectMake(200, 10 + h, 50, 25);
}

//高度自适应方法
+(CGFloat)heightWithText:(NSString *)text width:(CGFloat)width{
    NSDictionary *dic = @{NSFontAttributeName: [UIFont systemFontOfSize:17]};
    CGSize size = CGSizeMake(width, 1000);
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}





- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
